package cn.innosmart.aq.bean;

import java.util.ArrayList;

import cn.innosmart.aq.util.DeviceConstant;
import cn.innosmart.aq.util.SystemConstant;

/**
 * Created by David on 2015/8/17.
 */
public class TriggerBean {
    private String address;
    private ArrayList<ValueConditionBean> valueConditionBeans;

    public TriggerBean() {
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public ArrayList<ValueConditionBean> getValueConditionBeans() {
        return valueConditionBeans;
    }

    public void setValueConditionBeans(ArrayList<ValueConditionBean> valueConditionBeans) {
        this.valueConditionBeans = valueConditionBeans;
    }

    @Override
    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        DeviceBean deviceBean = SystemConstant.deviceBeanHashMap.get(address);
        if (deviceBean.getFunctype() == DeviceConstant.FUNCTYPE_WATERLEVER) {
            for (ValueConditionBean valueConditionBean : valueConditionBeans) {
                if (valueConditionBean.getThreshold() == 1) {
                    if (stringBuilder.length() != 0)
                        stringBuilder.append(";");
                    stringBuilder.append("水位偏低");
                }
                if (valueConditionBean.getThreshold() == 2) {
                    if (stringBuilder.length() != 0)
                        stringBuilder.append(";");
                    stringBuilder.append("水位偏高");
                }
            }
            return stringBuilder.toString();
        }
        if (deviceBean.getFunctype() == DeviceConstant.FUNCTYPE_SWITCH) {
            for (ValueConditionBean valueConditionBean : valueConditionBeans) {
                if (valueConditionBean.getThreshold() == 1) {
                    if (stringBuilder.length() != 0)
                        stringBuilder.append(";");
                    stringBuilder.append("水位偏低");
                }
                if (valueConditionBean.getThreshold() == 2) {
                    if (stringBuilder.length() != 0)
                        stringBuilder.append(";");
                    stringBuilder.append("水位偏高");
                }
            }
            return stringBuilder.toString();
        }
        ValueConditionBean valueConditionBean = valueConditionBeans.get(0);
        if (deviceBean.getFunctype() == DeviceConstant.FUNCTYPE_TEMPERATURE) {
            stringBuilder.append("温度 ");
            stringBuilder.append(valueConditionBeans.get(0).getOp());
            stringBuilder.append(DeviceConstant.caculateValue(deviceBean.getSensorunit(), valueConditionBean.getThreshold()));
        } else {
            stringBuilder.append("PH ");
            stringBuilder.append(valueConditionBeans.get(0).getOp());
            stringBuilder.append(DeviceConstant.caculateValue(deviceBean.getSensorunit(), valueConditionBean.getThreshold()));
        }
        return stringBuilder.toString();
    }

}
